<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>大眼窝进销存系统--配货单</title>
<load href='__PUBLIC__/bootstrap/css/bootstrap.min.css' />
<load href='__PUBLIC__/Css/style.css' />
<style type="text/css">
	.order_info{height:667px;font-size:20px; margin-left: 5px; border-top: 1px dashed black;padding-top: 20px;}
	.order_info .row {min-height: 28px;line-height: 28px;}
	.table-bordered th, .table-bordered td{border-left:2px solid black}
	.table-bordered {border: 2px solid black;}
	.table td,.table th {border-top: 2px solid black;}
</style>
<style media="print" type="text/css"> 
.Noprint{display:none;} 
.PageNext{page-break-after: always;} 
</style> 
<?php 
//必须按product_id排序，才能使用合并方法
	function merge_order_detail(&$order_detail,$sale_detail){
        foreach ($sale_detail as $key => $value) {
            __merge_order_detail($order_detail,$sale_detail,$value,$key);
        }
        return $order_detail;
    }

    function __merge_order_detail(&$order_detail,$sale_detail,$value,$key){
       
            if($key == 0)
                $order_detail[0] = $value;
            else{
                if( $value['product_id'] != 0 && 
                	$value['product_id'] == $sale_detail[$key-1]['product_id']
                    ){
                    if(is_array($order_detail[$key-1])){
                       $order_detail[$key-1]['number'] += $value['number'];
                        $order_detail[$key-1]['total'] += $value['total']; 
                    }else{
                        __merge_order_detail($order_detail,$sale_detail,$value,$key-1);
                    }
                    
                }else
                   $order_detail[$key] = $value;
            }
        return $order_detail;
    }
 ?>
</head>
<body>
<div id="main" class="main" >
<div class="heading Noprint"	>
   <span>大眼窝配货单</span> <span class="offset3"> <a href="__URL__/export_invoice/oid/{$_REQUEST.oid}" class="btn btn-primary"> <i class="icon-download-alt  icon-white"></i>导出CSV</a>  <button onClick="print_invoice()" class="btn btn-primary offset1"><i class="icon-print  icon-white"></i>打印</button></span>
</div>
<?php $p_index = 1; ?>
 <volist name="orders" id="vo">
		<?php $is_all_virtual = is_all_virtual($vo['id']); ?>
		<eq name="is_all_virtual" value="0"> <!--如果全部是虚拟物品，则不显示配货单-->
		<div class="order_info" >
			<!--
			<div class="row">
				<div class="span6">
					<img src="__APP__/Public/upc/code/{$vo.sale_no|getMergeNo}/hi/20" />
				</div> 
			</div> -->
			<div class="row">
				<div class="span1" style="font-size:30px">{$p_index++}</div>
				<div class="span4"><strong>订单号：{$vo.sale_no|getMergeNo} ({$vo.order_source_id|getModelName='Order_source'})</strong></div>
				<div class="span3" >会员名：{$vo.customer_name}</div>
				<div class="span4">配货日期：{:date('Y-m-d H:i:s')}</div>
			</div>
			
			<div class="row">
				<div class="span1">&nbsp;</div>
				<div class="span4">收货人:{$vo.shipping_name}</div>
				<div class="span3" >电话：{$vo.phone}</div>
				<div class="span4">手机：{$vo.mobile}</div>
			</div>
			<div class="row">
				<div class="span12">地址：{$vo.address}</div>
			</div>
			<div class="row">
				<div class="span12">客户留言:{$vo.customer_msg}</div>
			</div>
			<div class="row">
				<div class="span12">
					<table class="table table-condensed table-bordered">
	                <tr>
	                    <td>序</td><td>商品名称</td>
	                    <!--<th width="80">规格</th><th>编号</th><th>商品名称</th> <th>仓位</th> -->
	                    <td class="span1">价格</td><td class="span1">数量</td><td class="span2">单位</td><td class="span1">小计</td>
	                </tr>
	                <php>
	                	$condition = array ('sale_id' => array ('in', explode ( ',', $vo['id'] ) ) );
	                	
	                	$sale_details = M('Sale_detail')->where($condition)->order('product_id asc')->findAll(); 
	                	$order_detail = array();
	                	$order_detail = merge_order_detail($order_detail,$sale_details);
	                	$total_number = 0; //实体产品总数量
	                	$sum_price = 0.00;  //总货款
	                </php>
	                <volist name="order_detail" id="sa">
	                	<?php $is_virtual = getModelName($sa['product_id'],'Product','is_virtual'); ?>
	                	<eq name="is_virtual " value="0"><!--非虚拟物品，则打印配货单-->
	                    <tr>
	                        <td>{$key+1}</td>
	                        <td> <eq name="sa.product_id" value="0"> {$sa.sale_title}{$sa.options}<else/> {$sa.product_id|getModelName='Product'} </eq></td>
	                        
	                        <td>{$sa.price}</td>
	                        <td>{$sa.number}</td>
	                        <td>{$sa.product_id|getProductUnit}</td>
	                        <td>{$sa.total}</td>
	                    </tr>
	                    <?php $total_number+= $sa['number'];  $sum_price +=$sa['total'];  ?> 
	                	</eq>
	                </volist>
	                <tr> <td colspan=2>货款：{$sum_price} </td><td>合计</td> <td>{$total_number}</td><td></td> <td>{$sum_price}</td> </tr>
	            </table>
				</div>
			</div>
		</div>
		</eq>
	</volist>

</div>
</body>
</html>
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
function print_invoice(){
    if(window.confirm("确实要打印快递单吗？")){
     var oid = "{$_REQUEST.oid}";
     jQuery.post(
       '__URL__/print_invoice',
        {   oid:oid
        },
        function(data){
	   data = data.data;
           if(data)
	      window.print();
        },

        'json'
        );
   }else
       return false;
}
</script>
